package everyday;

import org.junit.jupiter.api.Test;

public class T1147 {
    StringBuffer text;
    int mid;
    int len;
    public int longestDecomposition(String text) {
        this.len = text.length();
        this.text = new StringBuffer(text);
        mid = (len + 1) / 2;
        return dp(0);
    }


    public int dp(int left) {
        char c = text.charAt(left);
        for (int i =len - 1 - left ; i >=mid ; i--) {
            if (c == text.charAt(i) && text.substring(left, len - i).equals(text.substring(i, len - left))) {
                int res=i == mid ? 2+len % 2 : dp(len - i) + 2;
                return res;
            }
        }
        return 1;
    }

    @Test
    public void test() {
        System.out.println(longestDecomposition("antaprezatepzapreanta"));
    }
}
